"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketConnectionManager = void 0;
const ErrorCode_1 = require("../../../config/ErrorCode");
class SocketConnectionManager {
    constructor() {
        this.socketConnMap = new Map();
    }
    /*
   增加客户端socket连接
    */
    addSocketConnection(conn) {
        this.socketConnMap.set(conn.id, conn);
    }
    getSocketConnection(id) {
        return this.socketConnMap.get(id);
    }
    getSocketConnectionByUser(account) {
        let result = [];
        this.socketConnMap.forEach((conn, key) => {
            if (!conn.isClosing && conn.account && conn.account == account) {
                result.push(conn);
                return;
            }
        });
        return result;
    }
    killAllByWeihu() {
        this.socketConnMap.forEach((conn, key) => {
            if (!conn.isClosing && conn.account) {
                conn.sendErrorToClient(0, ErrorCode_1.ErrorCode.Code.Server_Weihu, ErrorCode_1.ErrorCode.code2Msg.get(ErrorCode_1.ErrorCode.Code.Server_Weihu));
                conn.gotoClose();
            }
        });
    }
    clearAll() {
        // this.socketConnMap.forEach((conn: SocketConnection, key: number) => {
        //     if (!conn.isClosing && conn.account) {
        //         this.sendErrorToClient(socketConnect, ErrorCode.Code.Server_Weihu, ErrorCode.code2Msg.get(ErrorCode.Code.Server_Weihu))
        //         HallServer_SocketMsgHandler.sendErrorToClient(conn, err)
        //     }
        // });
    }
    /*
    删除客户端socket连接
     */
    removeSocketConnection(removeOne) {
        if (!removeOne) {
            return;
        }
        this.socketConnMap.delete(removeOne.id);
    }
    getConnectionCount() {
        let count = 0;
        this.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                if (conn.user) {
                    count++;
                }
                // Logger.log("getConnectionCount==", conn.account, conn.user)
            }
        });
        return count;
    }
    getOnlineUserList() {
        let useridList = [];
        SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                if (conn.user) {
                    useridList.push(conn.user.userid);
                }
            }
        });
        return useridList;
    }
    getClubOnlineCount(clubid) {
        let count = 0;
        SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                if (conn.user) {
                }
            }
        });
        return count;
    }
    isUserOnline(userid) {
        let isOnline = false;
        SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                if (conn.user && conn.user.userid == userid) {
                    isOnline = true;
                    return;
                }
            }
        });
        return isOnline;
    }
    getSocketConnectionByUserid(userid) {
        let connection = null;
        this.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                if (conn.user && conn.user.userid == userid) {
                    connection = conn;
                    return conn;
                }
            }
        });
        return connection;
    }
    notify_club_open_or_close(clubid, state) {
        // this.socketConnMap.forEach((conn: SocketConnection, key: number) => {
        //     if (conn.isLogin()) {
        //         if (conn.user) {
        //             let club: ClubModel =  conn.user.getClub(clubid)
        //             if (club) {
        //                 club.state = state;
        //             }
        //         }
        //     }
        // });
    }
}
exports.SocketConnectionManager = SocketConnectionManager;
SocketConnectionManager.instance = new SocketConnectionManager();
